<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js">&quot;use strict&quot;;
Object.defineProperty(exports, &quot;__esModule&quot;, { value: true });
exports.UrlMatch = void 0;
var tslib_1 = require(&quot;tslib&quot;);
var abstract_match_1 = require(&quot;./abstract-match&quot;);
var uri_utils_1 = require(&quot;../parser/uri-utils&quot;);
<span id='global-property-wwwPrefixRegex'>/**
</span> * A regular expression used to remove the &#39;www.&#39; from URLs.
 */
var wwwPrefixRegex = /^(https?:\/\/)?(www\.)?/i;
<span id='global-property-protocolRelativeRegex'>/**
</span> * The regular expression used to remove the protocol-relative &#39;//&#39; from a URL
 * string, for purposes of formatting the anchor text. A protocol-relative URL
 * is, for example, &quot;//yahoo.com&quot;
 */
var protocolRelativeRegex = /^\/\//;
<span id='Autolinker-match-Url'>/**
</span> * @class Autolinker.match.Url
 * @extends Autolinker.match.AbstractMatch
 *
 * Represents a Url match found in an input string which should be Autolinked.
 *
 * See this class&#39;s superclass ({@link Autolinker.match.Match}) for more details.
 */
var UrlMatch =  (function (_super) {
    (0, tslib_1.__extends)(UrlMatch, _super);
<span id='Autolinker-match-Url-method-constructor'>    /**
</span>     * @method constructor
     * @param {Object} cfg The configuration properties for the Match
     *   instance, specified in an Object (map).
     */
    function UrlMatch(cfg) {
        var _this = _super.call(this, cfg) || this;
<span id='Autolinker-match-Url-property-type'>        /**
</span>         * @public
         * @property {&#39;url&#39;} type
         *
         * A string name for the type of match that this class represents. Can be
         * used in a TypeScript discriminating union to type-narrow from the
         * `Match` type.
         */
        _this.type = &#39;url&#39;;
<span id='Autolinker-match-Url-cfg-url'>        /**
</span>         * @cfg {String} url (required)
         *
         * The url that was matched.
         */
        _this.url = &#39;&#39;; // default value just to get the above doc comment in the ES5 output and documentation generator
<span id='Autolinker-match-Url-cfg-urlMatchType'>        /**
</span>         * @cfg {&quot;scheme&quot;/&quot;www&quot;/&quot;tld&quot;} urlMatchType (required)
         *
         * The type of URL match that this class represents. This helps to determine
         * if the match was made in the original text with a prefixed scheme (ex:
         * &#39;http://www.google.com&#39;), a prefixed &#39;www&#39; (ex: &#39;www.google.com&#39;), or
         * was matched by a known top-level domain (ex: &#39;google.com&#39;).
         */
        _this.urlMatchType = &#39;scheme&#39;; // default value just to get the above doc comment in the ES5 output and documentation generator
<span id='Autolinker-match-Url-cfg-protocolRelativeMatch'>        /**
</span>         * @cfg {Boolean} protocolRelativeMatch (required)
         *
         * `true` if the URL is a protocol-relative match. A protocol-relative match
         * is a URL that starts with &#39;//&#39;, and will be either http:// or https://
         * based on the protocol that the site is loaded under.
         */
        _this.protocolRelativeMatch = false; // default value just to get the above doc comment in the ES5 output and documentation generator
<span id='Autolinker-match-Url-cfg-stripPrefix'>        /**
</span>         * @cfg {Object} stripPrefix (required)
         *
         * The Object form of {@link Autolinker#cfg-stripPrefix}.
         */
        _this.stripPrefix = {
            scheme: true,
            www: true,
        }; // default value just to get the above doc comment in the ES5 output and documentation generator
<span id='Autolinker-match-Url-cfg-stripTrailingSlash'>        /**
</span>         * @cfg {Boolean} stripTrailingSlash (required)
         * @inheritdoc Autolinker#cfg-stripTrailingSlash
         */
        _this.stripTrailingSlash = true; // default value just to get the above doc comment in the ES5 output and documentation generator
<span id='Autolinker-match-Url-cfg-decodePercentEncoding'>        /**
</span>         * @cfg {Boolean} decodePercentEncoding (required)
         * @inheritdoc Autolinker#cfg-decodePercentEncoding
         */
        _this.decodePercentEncoding = true; // default value just to get the above doc comment in the ES5 output and documentation generator
<span id='Autolinker-match-Url-property-protocolPrepended'>        /**
</span>         * @private
         * @property {Boolean} protocolPrepended
         *
         * Will be set to `true` if the &#39;http://&#39; protocol has been prepended to the {@link #url} (because the
         * {@link #url} did not have a protocol)
         */
        _this.protocolPrepended = false;
        _this.urlMatchType = cfg.urlMatchType;
        _this.url = cfg.url;
        _this.protocolRelativeMatch = cfg.protocolRelativeMatch;
        _this.stripPrefix = cfg.stripPrefix;
        _this.stripTrailingSlash = cfg.stripTrailingSlash;
        _this.decodePercentEncoding = cfg.decodePercentEncoding;
        return _this;
    }
<span id='Autolinker-match-Url-method-getType'>    /**
</span>     * Returns a string name for the type of match that this class represents.
     * For the case of UrlMatch, returns &#39;url&#39;.
     *
     * @return {String}
     */
    UrlMatch.prototype.getType = function () {
        return &#39;url&#39;;
    };
<span id='Autolinker-match-Url-method-getUrlMatchType'>    /**
</span>     * Returns a string name for the type of URL match that this class
     * represents.
     *
     * This helps to determine if the match was made in the original text with a
     * prefixed scheme (ex: &#39;http://www.google.com&#39;), a prefixed &#39;www&#39; (ex:
     * &#39;www.google.com&#39;), or was matched by a known top-level domain (ex:
     * &#39;google.com&#39;).
     *
     * @return {&quot;scheme&quot;/&quot;www&quot;/&quot;tld&quot;}
     */
    UrlMatch.prototype.getUrlMatchType = function () {
        return this.urlMatchType;
    };
<span id='Autolinker-match-Url-method-getUrl'>    /**
</span>     * Returns the url that was matched, assuming the protocol to be &#39;http://&#39; if the original
     * match was missing a protocol.
     *
     * @return {String}
     */
    UrlMatch.prototype.getUrl = function () {
        var url = this.url;
        // if the url string doesn&#39;t begin with a scheme, assume &#39;http://&#39;
        if (!this.protocolRelativeMatch &amp;&amp;
            this.urlMatchType !== &#39;scheme&#39; &amp;&amp;
            !this.protocolPrepended) {
            url = this.url = &#39;http://&#39; + url;
            this.protocolPrepended = true;
        }
        return url;
    };
<span id='Autolinker-match-Url-method-getAnchorHref'>    /**
</span>     * Returns the anchor href that should be generated for the match.
     *
     * @return {String}
     */
    UrlMatch.prototype.getAnchorHref = function () {
        var url = this.getUrl();
        return url.replace(/&amp;amp;/g, &#39;&amp;&#39;); // any &amp;amp;&#39;s in the URL should be converted back to &#39;&amp;&#39; if they were displayed as &amp;amp; in the source html
    };
<span id='Autolinker-match-Url-method-getAnchorText'>    /**
</span>     * Returns the anchor text that should be generated for the match.
     *
     * @return {String}
     */
    UrlMatch.prototype.getAnchorText = function () {
        var anchorText = this.getMatchedText();
        if (this.protocolRelativeMatch) {
            // Strip off any protocol-relative &#39;//&#39; from the anchor text
            anchorText = stripProtocolRelativePrefix(anchorText);
        }
        if (this.stripPrefix.scheme) {
            anchorText = stripSchemePrefix(anchorText);
        }
        if (this.stripPrefix.www) {
            anchorText = stripWwwPrefix(anchorText);
        }
        if (this.stripTrailingSlash) {
            anchorText = removeTrailingSlash(anchorText); // remove trailing slash, if there is one
        }
        if (this.decodePercentEncoding) {
            anchorText = removePercentEncoding(anchorText);
        }
        return anchorText;
    };
    return UrlMatch;
}(abstract_match_1.AbstractMatch));
exports.UrlMatch = UrlMatch;
// Utility Functionality
<span id='Autolinker-match-Url-method-stripSchemePrefix'>/**
</span> * Strips the scheme prefix (such as &quot;http://&quot; or &quot;https://&quot;) from the given
 * `url`.
 *
 * @private
 * @param {String} url The text of the anchor that is being generated, for
 *   which to strip off the url scheme.
 * @return {String} The `url`, with the scheme stripped.
 */
function stripSchemePrefix(url) {
    return url.replace(uri_utils_1.httpSchemePrefixRe, &#39;&#39;);
}
<span id='Autolinker-match-Url-method-stripWwwPrefix'>/**
</span> * Strips the &#39;www&#39; prefix from the given `url`.
 *
 * @private
 * @param {String} url The text of the anchor that is being generated, for
 *   which to strip off the &#39;www&#39; if it exists.
 * @return {String} The `url`, with the &#39;www&#39; stripped.
 */
function stripWwwPrefix(url) {
    return url.replace(wwwPrefixRegex, &#39;$1&#39;); // leave any scheme ($1), it one exists
}
<span id='Autolinker-match-Url-method-stripProtocolRelativePrefix'>/**
</span> * Strips any protocol-relative &#39;//&#39; from the anchor text.
 *
 * @private
 * @param {String} text The text of the anchor that is being generated, for which to strip off the
 *   protocol-relative prefix (such as stripping off &quot;//&quot;)
 * @return {String} The `anchorText`, with the protocol-relative prefix stripped.
 */
function stripProtocolRelativePrefix(text) {
    return text.replace(protocolRelativeRegex, &#39;&#39;);
}
<span id='Autolinker-match-Url-method-removeTrailingSlash'>/**
</span> * Removes any trailing slash from the given `anchorText`, in preparation for the text to be displayed.
 *
 * @private
 * @param {String} anchorText The text of the anchor that is being generated, for which to remove any trailing
 *   slash (&#39;/&#39;) that may exist.
 * @return {String} The `anchorText`, with the trailing slash removed.
 */
function removeTrailingSlash(anchorText) {
    if (anchorText.charAt(anchorText.length - 1) === &#39;/&#39;) {
        anchorText = anchorText.slice(0, -1);
    }
    return anchorText;
}
<span id='Autolinker-match-Url-method-removePercentEncoding'>/**
</span> * Decodes percent-encoded characters from the given `anchorText`, in
 * preparation for the text to be displayed.
 *
 * @private
 * @param {String} anchorText The text of the anchor that is being
 *   generated, for which to decode any percent-encoded characters.
 * @return {String} The `anchorText`, with the percent-encoded characters
 *   decoded.
 */
function removePercentEncoding(anchorText) {
    // First, convert a few of the known % encodings to the corresponding
    // HTML entities that could accidentally be interpretted as special
    // HTML characters
    var preProcessedEntityAnchorText = anchorText
        .replace(/%22/gi, &#39;&amp;quot;&#39;) // &quot; char
        .replace(/%26/gi, &#39;&amp;amp;&#39;) // &amp; char
        .replace(/%27/gi, &#39;&amp;#39;&#39;) // &#39; char
        .replace(/%3C/gi, &#39;&amp;lt;&#39;) // &lt; char
        .replace(/%3E/gi, &#39;&amp;gt;&#39;); // &gt; char
    try {
        // Now attempt to decode the rest of the anchor text
        return decodeURIComponent(preProcessedEntityAnchorText);
    }
    catch (e) {
        // Invalid % escape sequence in the anchor text
        return preProcessedEntityAnchorText;
    }
}
//# sourceMappingURL=url-match.js.map</pre>
</body>
</html>
